package com.icat.house.service;

import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.icat.house.model.HouseInfo;
import com.jfinal.kit.JsonKit;

public class HouseService {

	public static final JSONArray findHouse(int buildings) {
		JSONArray jsonArray = new JSONArray();
		List<HouseInfo> list = HouseInfo.dao.findHouseByBuildings(buildings);
		JSONArray array = new JSONArray();
		for (int i = 0; i < list.size(); i++) {
			int unit = list.get(i).getInt("unit");
			int unit2 = 0;
			if (list.size() > i + 1) {
				unit2 = list.get(i + 1).getInt("unit");
			}
			array.add(JSONObject.parseObject(JsonKit.toJson(list.get(i))));
			if (unit != unit2) {
				jsonArray.add(array);
				array = new JSONArray();
			}
		}
		return jsonArray;
	}
}
